package cn.com.blueInfo.bpm.system.controller;

import cn.com.blueInfo.bpm.common.controller.BaseController;
import cn.com.blueInfo.bpm.common.validation.Create;
import cn.com.blueInfo.bpm.common.validation.Update;
import cn.com.blueInfo.bpm.common.validation.UpdatePartial;
import cn.com.blueInfo.bpm.system.request.DynamicFormDTO;
import cn.com.blueInfo.bpm.system.response.DynamicFormVO;
import cn.com.blueInfo.bpm.system.service.DynamicFormService;
import cn.com.blueInfo.utils.result.ResultInfo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.groups.Default;
import java.util.List;

/**
 * 动态表单表 前端控制器
 * @author suxch
 * @since 2025-08-24 01:37:55
 */
@Tag(name = "动态表单 接口")
@RestController
@RequestMapping("/system/dynamicForm")
public class DynamicFormController extends BaseController {

    @Autowired
    private DynamicFormService dynamicFormService;

    /**
     * 新建动态表单
     * @param dynamicFormDTO 动态表单参数
     * @return ResultInfo
     */
    @Operation(summary = "新增动态表单")
    @PostMapping("/addInfo")
    public ResultInfo<Integer> createDynamicForm(
            @Validated({Create.class, Default.class}) @RequestBody DynamicFormDTO dynamicFormDTO) {
        return dynamicFormService.addDynamicForm(dynamicFormDTO);
    }

    /**
     * 批量新建动态表单
     * @param dynamicFormDTOList 动态表单参数列表
     * @return ResultInfo
     */
    @Operation(summary = "批量新建动态表单")
    @PostMapping("/addInfoList")
    public ResultInfo<Integer> batchCreateDynamicForm(
            @Validated({Create.class, Default.class}) @RequestBody List<DynamicFormDTO> dynamicFormDTOList) {
        return dynamicFormService.batchAddDynamicForm(dynamicFormDTOList);
    }

    /**
     * 根据ID删除动态表单
     * @param dynamicFormId 动态表单ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID删除动态表单")
    @DeleteMapping("/removeInfo/{dynamicFormId}")
    public ResultInfo<Integer> deleteDynamicFormById(
            @Parameter(name = "ID") @PathVariable Long dynamicFormId) {
        return dynamicFormService.removeDynamicForm(dynamicFormId);
    }

    /**
     * 批量根据ID删除动态表单
     * @param dynamicFormIdList 动态表单ID列表
     * @return ResultInfo
     */
    @Operation(summary = "批量根据ID删除动态表单")
    @DeleteMapping("/removeInfoList/{dynamicFormIdList}")
    public ResultInfo<Integer> batchDeleteDynamicFormById(
            @Parameter(name = "ID") @PathVariable List<Long> dynamicFormIdList) {
        return dynamicFormService.batchRemoveDynamicForm(dynamicFormIdList);
    }

    /**
     * 根据ID全量更新动态表单
     * @param dynamicFormId 动态表单ID
     * @param dynamicFormDTO 动态表单参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID全量更新动态表单")
    @PutMapping("/modifyInfo/{dynamicFormId}")
    public ResultInfo<Integer> updateDynamicFormFull(
            @Parameter(name = "ID") @PathVariable Long dynamicFormId,
            @Validated({Update.class, Default.class}) @RequestBody DynamicFormDTO dynamicFormDTO) {
        validateUpdateId(dynamicFormId, dynamicFormDTO.getId());
        return dynamicFormService.modifyDynamicForm(dynamicFormDTO);
    }

    /**
     * 根据ID部分更新动态表单
     * @param dynamicFormId 动态表单ID
     * @param dynamicFormUpdatePartialDTO 动态表单参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID部分更新动态表单")
    @PatchMapping("/modifyPartialInfo/{dynamicFormId}")
    public ResultInfo<Integer> updateDynamicFormPartial(
            @Parameter(name = "ID") @PathVariable Long dynamicFormId,
            @Validated({UpdatePartial.class, Default.class}) @RequestBody
            DynamicFormDTO.UpdatePartialDTO dynamicFormUpdatePartialDTO) {
        validateUpdateId(dynamicFormId, dynamicFormUpdatePartialDTO.getId());
        return dynamicFormService.modifyDynamicFormPartial(dynamicFormUpdatePartialDTO);
    }

    /**
     * 根据ID查询动态表单
     * @param dynamicFormId 动态表单ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID查询动态表单")
    @GetMapping("/getInfo/{dynamicFormId}")
    public ResultInfo<DynamicFormVO> getDynamicFormById(
            @Parameter(name = "ID") @PathVariable Long dynamicFormId) {
        return dynamicFormService.queryDynamicFormById(dynamicFormId);
    }

    /**
     * 分页查询动态表单
     * @param dynamicFormQueryDTO 动态表单参数
     * @return ResultInfo
     */
    @Operation(summary = "分页查询动态表单")
    @GetMapping("/getInfos")
    public ResultInfo<Page<DynamicFormVO>> getDynamicFormPage(
            @Validated DynamicFormDTO.QueryDTO dynamicFormQueryDTO) {
        return dynamicFormService.queryDynamicFormPage(dynamicFormQueryDTO);
    }

    /**
     * 根据条件查询动态表单
     * @param dynamicFormQueryDTO 动态表单参数
     * @return ResultInfo
     */
    @Operation(summary = "根据条件查询动态表单")
    @GetMapping("/getInfoList")
    public ResultInfo<List<DynamicFormVO>> getDynamicFormList(
            @Validated DynamicFormDTO.QueryDTO dynamicFormQueryDTO) {
        return dynamicFormService.queryDynamicFormList(dynamicFormQueryDTO);
    }

}
